export const formConf = {
	formRef: 'elForm',
	formModel: 'formData',
	size: 'medium',
	labelPosition: 'right',
	labelWidth: '',
	formRules: 'rules',
	gutter: 15,
	disabled: false,
	span: 24,
	formBtns: true,
}

export const inputComponents = [
	{
		label: '单行文本：',
		tag: 'el-input',
		placeholder: '请输入提示文字',
		type: 'input',
		defaultValue: undefined,
		labelWidth: 85,
		clearable: true,
		code: 'input',
		renderer: 'Input',
		width: 200,
		show: true,
	},
	{
		label: '下拉选择：',
		type: 'select',
		code: 'select',
		renderer: 'Select',
		tag: 'el-select',
		placeholder: '请输入提示文字',
		defaultValue: undefined,
		labelWidth: 85,
		clearable: true,
		width: 200,
		show: true,
		sql: null,
		data: '',
		options: [
			{
				label: '选项一',
				value: 1,
			},
			{
				label: '选项二',
				value: 2,
			},
		],
		class: 'systemInput',
	},
	{
		label: '日期选择：',
		code: 'datePicker',
		tag: 'el-date-picker',
		clearable: true,
		renderer: 'DatePicker',
		tagIcon: 'time',
		type: 'date',
		placeholder: undefined,
		width: 200,
		defaultValue: null,
		labelWidth: 85,
		style: { width: '100%' },
		format: 'yyyy-MM-dd',
		'value-format': 'yyyy-MM-dd',
		class: 'systemInput',
		show: true,
	},
	{
		label: '时间日期选择：',
		clearable: true,
		renderer: 'DatePicker',
		code: 'dateTimePicker',
		tag: 'el-date-picker',
		width: 200,
		tagIcon: 'time',
		type: 'datetime',
		placeholder: undefined,
		defaultValue: null,
		labelWidth: 120,
		style: { width: '100%' },
		format: 'yyyy-MM-dd HH:mm:ss',
		'value-format': 'yyyy-MM-dd HH:mm:ss',
		class: 'systemInput',
		show: true,
	},
	{
		label: '自定义事件：',
		tag: 'el-input',
		placeholder: '请输入提示文字',
		type: 'eventInput',
		width: 200,
		defaultValue: undefined,
		labelWidth: 100,
		clearable: true,
		code: 'input',
		renderer: 'Input',
		show: true,
	},
]

export const buttonComponents = [
	{
		label: '普通按钮',
		tag: 'el-button',
		code: 'button',
		type: 'button',
		defaultValue: '普通按钮',
		width: 100,
		labelWidth: null,
		style: { width: '100%' },
		contentType: 1,
		params: '{"cellParams":["@sj_id","@@sj_id"]}',
	},
	{
		label: '流程按钮',
		tag: 'el-button',
		code: 'button',
		type: 'flowButton',
		defaultValue: '流程按钮',
		width: 120,
		labelWidth: null,
		sql: '',
		url: '',
		style: { width: '100%', background: '#00BFFF', color: '#fff' },
	},
]

export const layoutComponents = [
	{
		layout: 'rowFormItem',
		tagIcon: 'row',
		type: 'default',
		justify: 'start',
		align: 'top',
		span: 24,
		label: '行容器',
		layoutTree: true,
		children: [],
	},
]

// 组件rule的触发方式，无触发方式的组件不生成rule
export const trigger = {
	'el-input': 'blur',
	'el-input-number': 'blur',
	'el-select': 'change',
	'el-radio-group': 'change',
	'el-checkbox-group': 'change',
	'el-cascader': 'change',
	'el-time-picker': 'change',
	'el-date-picker': 'change',
	'el-rate': 'change',
}

// TODO 页面配置按钮区方法汇总
export const fun = {
	'businessButtonAdd': {
		'method': `
        let x=1,y=2;
        this.buttonAdd(x,y);
    `,
	},
	'businessButtonEdit': {
		'method': `
        if (this.checkedData.length === 0) {
            this.message("请选择需要编辑的数据", 3);
            return;
          }
          if (this.checkedData.length > 1) {
            this.message("不能同时编辑多条数据", 3);
            return;
          }
          const detail = JSON.parse(JSON.stringify(this.checkedData[0]));
          this.wpId = await this.getWpId(detail);
          if (!this.wpId) {
            this.message("没有表单 ID 无法编辑", 3);
            return;
          }
          if (!detail[this.pageContent.primaryName]) {
            this.message("没有主键无法编辑", 3);
            return;
          }
        editAut({
            funcId: this.params && this.params.id ? null : this.menuId,
            funcCode: this.params && this.params.id ? this.params.menuCode : null,
            tableName: this.pageContent.tableName,
            id: detail[this.pageContent.primaryName],
            keyName: this.pageContent.primaryName,
          }).then((res) => {
            if (res.success) {
              this.workId = detail[this.pageContent.primaryName];
              this.funcName = this.pageContent.text;
              this.tdeptId = this.$store.state.user.info.deptId;
              if (this.params && this.params.businessInfo) {
                if (Object.keys(this.params.businessInfo).length > 0) {
                  this.businessInfoParam = this.params.businessInfo;
                }
              }
              if (this.params && this.params.cellParams) {
                this.formateInitParam();
              } else {
                this.cellViewShow = true;
              }
            } else {
              this.message("没有编辑权限", 3);
              return;
            }
          }); 
        `,
	},
	'businessButtonDelete': {
		'method': `
        if (this.checkedData.length === 0) {
            this.message("请选择需要删除的数据", 3);
            return;
          }
          let ids = [];
          this.checkedData.forEach((item) => {
            ids.push(item[this.pageContent.primaryName]);
          });
          this.messageBox("确认删除？").then((c) => {
            if (c.action) {
              pageRemove({
                pageId: this.pageContent.id,
                values: ids,
                menuId: this.params && this.params.id ? null : this.menuId,
                menuCode:
                  this.params && this.params.id ? this.params.menuCode : null,
              }).then((res) => {
                if (res.success) {
                  this.search(this.pageIndex);
                  this.message(res.msg, 1);
                } else {
                  this.message("数据已经存在流程中，不允许删除", 3);
                }
              });
            }
          });
        `,
	},
	'businessButtonViewFlow': {
		'method': `
        if (this.checkedData.length > 1) {
            this.message("不能同时查看多个流程", 3);
            return;
          }
          if (this.checkedData.length === 0) {
            this.message("请选择需要查看的流程", 3);
            return;
          }
          if (this.checkedData[0].WF_STATE === 0) {
            this.message("流程未上报", 3);
            return;
          }
          this.flowViewShow = true;
          this.wfInstId = this.checkedData[0].WFINST_ID;
        `,
	},
	'businessButtonExport': {
		'method': `
            const arr = await this.getFormattingCondition();
            pageExport({
            pageId: this.pageContent.id,
            menuId: this.params && this.params.id ? null : this.menuId,
            menuCode: this.params && this.params.id ? this.params.menuCode : null,
            params: arr,
            }).then((res) => {
            if (res.success) {
                window.open(process.env.VUE_APP_BASE_API + res.info);
                this.message(res.msg, 1);
            } else {
                this.message(res.msg, 3);
                return;
            }
            });
        `,
	},
	'businessButtonImport': {
		'method': `
        getFillDept({
            funcId: this.params && this.params.id ? null : this.menuId,
            funcCode: this.params && this.params.id ? this.params.menuCode : null,
            type: 2,
          }).then((res) => {
            if (res.info.length === 1) {
              this.tdeptId = res.info[0].id;
              this.form = {
                handleWay: 1,
                file: "",
              };
              this.file = null;
              this.errorMessageShow = false;
              this.importFileDialog = true;
            } else {
              this.deptMap = res.info;
              this.deptMapShow = true;
            }
          });
        `,
	},
}
export const statisticalComponents = []
